document.querySelector('#btn-register').addEventListener('click', async function () {
  const form = document.querySelector('.register-form')
  const data = serialize(form, { empty: true, hash: true })
  const { username, password } = data
  if (username === '' || password === '') {
    showToast('用户名或密码不能为空')
    return
  }
  if (username.length < 8 || username.length > 30 || password.length < 6 || password.length > 30) {
    showToast('用户名的长度为8-30，密码的长度为6-30')
    return
  }
  try {
    const res = await axios.post('/register', {
      username,
      password
    })
    showToast(res.message)
  } catch (error) {
    showToast(error.response.data.message)
  }
})
